<?php
include '../login/db_connect.php';
include '../login/functions.php';
$query_test ="SHOW EVENTS";
if ($result = $mysqli->query ( $query_test)) {
	while($row = $result->fetch_assoc()){
		$now=new DateTime();
		$now->format('Y-m-d H:i:s');
		$current=new DateTime($row['Execute at']);
		if($current<$now){
			$length=strlen($row['Name']);
			$vendor=substr($row['Name'],6,$length-6);
			$query_alter ="ALTER EVENT ".$row['Name']." ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 SECOND DO UPDATE orders SET active='0' WHERE vendor='".$vendor."' AND active='1'";
			$res = $mysqli->query ( $query_alter);
		}
	}
	
}
?>